import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { getSimpleUserList } from '#/api/system/user';
import { getRangePickerDefaultProps } from '#/utils';

import { $t } from '#/locales';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'userId',
      label: $t('views.ai.common.user'),
      component: 'ApiSelect',
      componentProps: {
        api: getSimpleUserList,
        labelField: 'nickname',
        valueField: 'id',
      },
    },
    {
      fieldName: 'prompt',
      label: $t('views.ai.mindMap.manager.prompt'),
      component: 'Input',
    },
    {
      fieldName: 'createTime',
      label: $t('common.createTime'),
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: $t('views.common.id'),
      minWidth: 180,
      fixed: 'left',
    },
    {
      minWidth: 180,
      title: $t('views.ai.common.user'),
      slots: { default: 'userId' },
    },
    {
      field: 'prompt',
      title: $t('views.ai.mindMap.manager.prompt'),
      minWidth: 180,
    },
    {
      field: 'generatedContent',
      title: $t('views.ai.mindMap.manager.generatedContent'),
      minWidth: 300,
    },
    {
      field: 'model',
      title: $t('views.ai.common.modelName'),
      minWidth: 180,
    },
    {
      field: 'createTime',
      title: $t('common.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'errorMessage',
      title: $t('views.ai.mindMap.manager.errorMessage'),
      minWidth: 180,
    },
    {
      title: $t('common.action'),
      width: 130,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
